package com.qlslylq.ad.sdk.core.mgr;

import android.text.TextUtils;

import com.qlslylq.ad.sdk.application.AdMergeSDKApp;
import com.qlslylq.ad.sdk.model.rsp.MediaWebVO;
import com.qlslylq.ad.sdk.util.GsonUtils;
import com.qlslylq.ad.sdk.util.SPUtils;

/**
 * created by qlslylq <br/>
 * on 2022/4/27 <br/>
 * 媒体配置管理类<br/>
 */
public class MediaConfigMgr {

    private static MediaConfigMgr instance;

    private MediaConfigMgr() {

    }

    public static MediaConfigMgr getInstance() {
        if (instance == null) {
            instance = new MediaConfigMgr();
        }
        return instance;
    }

    /**
     * 获取媒体配置<br/>
     */
    public MediaWebVO getMediaConfig() {
        try {
            String jo = (String) SPUtils.get(AdMergeSDKApp.getInstance(), SPUtils.KEY_MEDIA_CONFIG, null);
            if (TextUtils.isEmpty(jo)) {
                return null;
            }
            MediaWebVO item = GsonUtils.gsonToBean(jo, MediaWebVO.class);
            return item;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 设置媒体配置<br/>
     */
    public void setMediaConfig(MediaWebVO item) {
        try {
            if (item == null) {
                return;
            }
            String jo = GsonUtils.gsonString(item);
            SPUtils.put(AdMergeSDKApp.getInstance(), SPUtils.KEY_MEDIA_CONFIG, jo);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
